// 常用中文姓氏
const surnames = ['王', '李', '张', '刘', '陈', '杨', '赵', '黄', '周', '吴'];
// 常用中文名字
const givenNames = ['伟', '芳', '娜', '秀英', '敏', '静', '丽', '强', '磊', '军'];
// 科室列表
const departments = ['呼吸内科', '心血管内科', '神经内科', '消化内科', '内分泌科'];

// 诊断结果
const diagnoses = [
  '慢性阻塞性肺疾病(COPD)',
  '支气管哮喘',
  '肺炎',
  '肺气肿',
  '支气管扩张',
  '间质性肺病'
];

// 生成随机患者姓名
const getRandomName = () => {
  const surname = surnames[Math.floor(Math.random() * surnames.length)];
  const givenName = givenNames[Math.floor(Math.random() * givenNames.length)];
  return `${surname}${givenName}`;
};

// 生成随机手机号
const getRandomPhone = () => {
  const prefix = ['138', '139', '150', '151', '152', '157', '188'];
  return `${prefix[Math.floor(Math.random() * prefix.length)]}${Math.floor(Math.random() * 100000000).toString().padStart(8, '0')}`;
};

// 生成随机日期
const getRandomDate = () => {
  const year = 2023;
  const month = Math.floor(Math.random() * 12) + 1;
  const day = Math.floor(Math.random() * 28) + 1;
  return `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
};

// 病史信息选项
const medicalHistories = [
  '吸烟史15年，每日20支',
  '高血压病史8年，规律服药',
  '2型糖尿病史5年，胰岛素控制',
  '冠心病史3年，曾行PCI术',
  '无特殊病史',
  // ...其他病史
];

// 出院建议
const dischargeAdvices = [
  '定期复查肺功能，每3个月门诊随访',
  '严格戒烟，避免二手烟暴露',
  // ...其他建议
];

// 检查项目
const detailedExamTypes = [
  {name: '肺功能检查', details: 'FEV1/FVC 65%, FEV1 60%预计值'},
  // ...其他检查
];

// 治疗方案
const detailedTreatments = [
  {
    name: '布地奈德福莫特罗吸入',
    details: '160/4.5μg 1吸 bid',
    instructions: '吸入后漱口，避免口腔真菌感染'
  },
  // ...其他治疗
];

// 生成随机检查结果
const getRandomExamination = () => {
  const count = Math.floor(Math.random() * 3) + 2;
  const exams = [];
  for (let i = 0; i < count; i++) {
    const exam = detailedExamTypes[Math.floor(Math.random() * detailedExamTypes.length)];
    exams.push({
      name: exam.name,
      result: exam.details,
      details: `检查方法: ${exam.name}，结果: ${exam.details}，临床意义: ${['无明显异常', '轻度异常', '需临床关注', '显著异常'][Math.floor(Math.random() * 4)]}`
    });
  }
  return exams;
};

// 生成随机治疗方案
const getRandomTreatment = () => {
  const count = Math.floor(Math.random() * 2) + 1;
  const plans = [];
  for (let i = 0; i < count; i++) {
    const treatment = detailedTreatments[Math.floor(Math.random() * detailedTreatments.length)];
    plans.push({
      name: treatment.name,
      plan: treatment.details,
      instructions: treatment.instructions,
      duration: `${Math.floor(Math.random() * 7) + 7}天`
    });
  }
  return plans;
};

// 生成8位不重复住院号
const generateUniqueRecordNumbers = (count) => {
  const numbers = new Set();
  while (numbers.size < count) {
    const num = Math.floor(10000000 + Math.random() * 90000000);
    numbers.add(num);
  }
  return Array.from(numbers);
};

const patientRecordNumbers = generateUniqueRecordNumbers(100);

// 生成mock患者数据
export const mockPatients = Array.from({ length: 100 }, (_, i) => {
  const gender = Math.random() > 0.5 ? '男' : '女';
  const age = Math.floor(Math.random() * 50) + 20;
  const status = Math.random() > 0.3 ? 'completed' : 'processing';
  const actionTypes = ['门诊', '复诊', '急诊', '会诊'];
  
  const selectedHistories = new Set();
  while(selectedHistories.size < Math.floor(Math.random() * 2) + 2) {
    selectedHistories.add(medicalHistories[Math.floor(Math.random() * medicalHistories.length)]);
  }
  
  const selectedAdvices = new Set();
  while(selectedAdvices.size < Math.floor(Math.random() * 3) + 3) {
    selectedAdvices.add(dischargeAdvices[Math.floor(Math.random() * dischargeAdvices.length)]);
  }

  return {
    recordNumber: patientRecordNumbers[i],
    patient: getRandomName(),
    date: getRandomDate(),
    phone: getRandomPhone(),
    action: actionTypes[Math.floor(Math.random() * actionTypes.length)],
    status,
    age,
    gender,
    department: departments[Math.floor(Math.random() * departments.length)],
    medicalHistory: Array.from(selectedHistories).join('；'),
    examination: getRandomExamination(),
    diagnosis: {
      main: diagnoses[Math.floor(Math.random() * diagnoses.length)],
      secondary: Math.random() > 0.7 ? '合并肺部感染' : '无',
      severity: ['轻度', '中度', '重度'][Math.floor(Math.random() * 3)],
      description: [
        '主要表现为活动后气促',
        '伴有慢性咳嗽、咳痰',
        '夜间症状加重',
        '季节性发作明显'
      ][Math.floor(Math.random() * 4)]
    },
    treatment: getRandomTreatment(),
    dischargeAdvice: Array.from(selectedAdvices).join('；'),
    followUp: `出院后${Math.floor(Math.random() * 4) + 1}周复诊`,
    lifestyleAdvice: [
      '戒烟限酒',
      '适量运动',
      '低盐饮食',
      '保持心情愉快'
    ][Math.floor(Math.random() * 4)]
  };
});

// 工作记录
export const initialWorkRecords = mockPatients.slice(0, 15).map(patient => ({
  recordNumber: patient.recordNumber,
  patient: patient.patient,
  date: patient.date,
  phone: patient.phone,
  action: patient.action,
  status: patient.status
}));

// 医生信息
export const mockDoctorInfo = {
  name: '王伟',
  title: '呼吸内科主任医师',
  department: '呼吸内科',
  workYears: '12年',
  certification: '中华医学会呼吸病学分会认证',
  avatar: 'https://randomuser.me/api/portraits/men/1.jpg',
  contact: '13800138000',
  email: 'wangwei@hospital.com'
};